home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / cstdio.arc / SRC.ARC / STRRCHR.A < prev    next >
Text File  |  1985-08-20  |  672b  |  32 lines

  1. ;    strrchr.a - find last occurrence of character in string.
  2. ;    (C) Copyright 1985 Cray Research Inc. - All Rights Reserved.
  3. ;    G. R. Mansfield.  85/08/20.
  4. ;    Ver 1.0-5820.
  5.  
  6.  
  7.     cseg
  8.     
  9.     public    strrchr_
  10.     public    rindex_
  11.     
  12. ;    char *strrchr(s, c)    /* return pointer to last occurrence of c */
  13. ;    char *rindex(s, c)    /* in s NULL if c is not in s */
  14. ;    char *s;
  15. ;    int c;
  16.  
  17. strrchr_:
  18. rindex_:
  19.     mov    bx,sp
  20.     mov    si,[bx+2]    ; s
  21.     mov    ah,[bx+4]    ; c
  22.     mov    bx,1        ; preset NULL
  23. stc1:    lodsb            ; next character in s
  24.     cmp    al,ah
  25.     jnz    stc2        ; if not found
  26.     mov    bx,si        ; pointer to c
  27. stc2:    or    al,al
  28.     jnz    stc1        ; loop to end of string
  29.     xchg    ax,bx        ; return pointer
  30.     dec    ax
  31.     ret
  32.